package com.laicunba.event.listener;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

import com.laicunba.event.UserCreateEvent;
import com.laicunba.pojo.SharedPacketItemDO;
import com.laicunba.pojo.UserDO;
import com.laicunba.service.SharedPacketItemService;
import com.laicunba.service.SharedPacketService;
import com.laicunba.service.exception.MyException;

@Component
public class DealSharedPacketWhenUserCreateListener implements ApplicationListener<UserCreateEvent> {
	private static final Logger LOG = Logger.getLogger(DealSharedPacketWhenUserCreateListener.class);
	@Autowired
	private SharedPacketItemService sharedPacketItemService;
	@Autowired
	private SharedPacketService sharedPacketService;

	@Override
	public void onApplicationEvent(UserCreateEvent event) {
		if (event.getSource() == null) {
			return;
		}
		try {
			UserDO userDO = (UserDO) event.getSource();
			sharedPacketService.make(userDO.getMobile());
		
		} catch (MyException e) {
			LOG.error("注册用户时,处理分享红包出错", e);
		}
	}

}
